package com.u.social.chat.server;

import com.u.social.chat.handler.AuthMsgChatHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;

/**
 * @program: awesome-spring
 * @description: WebSocket处理器
 * @author: Alex Wu
 * @createDate: 2025-03-14 16:08
 **/
public class WebSocketChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpObjectAggregator(65536));
        pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
//        pipeline.addLast(new SimpleChatHandler());
        pipeline.addLast(new AuthMsgChatHandler());
    }
}
